using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BuffHeavyArmor:BuffBase {

	public override string spriteName => "heavy armor";

	public BuffHeavyArmor(BuffSlot slot,Mob mob) : base(slot,mob) {
	}

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		MobEventHelper.lateDamage.SubscribeSingle(mob,Mob_LateDamaging);
	}
	protected override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		MobEventHelper.lateDamage.UnsubscribeSingle(mob,Mob_LateDamaging);
	}

	public override float stacks {
		get => _stacks; set {
			_stacks=Mathf.Clamp(Mathf.Floor(value),0,10);
			if(value<=0) RemoveSelf();
		}
	}

	void Mob_LateDamaging(object sender,DamageEventArgs e) {
		int levelDifference = e.stat.destructionLevel-(int)stacks;
		if(levelDifference<0) {
			e.stat.amount.AddMultiply(0.25f,1);
			float breakChance = Mathf.Pow(0.1f,e.stat.amount/20f);
			if(Utility.Chance(breakChance)) stacks--;
		} else {
			float breakChance = Mathf.Pow(0.5f,e.stat.amount/20f);
			if(Utility.Chance(breakChance)) stacks--;
		}
	}

}
